package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.SaleNewsActivity;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.SaleNewsBean;

import java.util.List;

import retrofit2.Call;


/**
 * Created by ${wenping} on 6/16/2017.
 */

public class SaleNewsPresenter extends BasePresenter {

    private SaleNewsActivity mSaleNewsActivity;
    private List<SaleNewsBean.TopicBean> mSaleNewsList;

    public SaleNewsPresenter(SaleNewsActivity saleNewsActivity) {
        mSaleNewsActivity = saleNewsActivity;
    }
    public void loadSaleNewsInfo(){
        Call<SaleNewsBean> salesNewsBeanCall = mApiService.getSaleNews("1","10");
        salesNewsBeanCall.enqueue(mCallback);
    }

    private static final String TAG = "SaleNewsPresenter";
    boolean openLog = false;
    @Override
    protected void onServerBug(int code) {
        if (openLog){
            Log.e(TAG, "onServerBug ");
        }
    }

    @Override
    protected void onConnectError(String message) {
        if (openLog) {
            Log.e(TAG, "onConnectError ");
        }
    }

    @Override
    protected void onSuccess(BaseBean bean) {
        SaleNewsBean saleNewsBean = (SaleNewsBean) bean;
        if (saleNewsBean!=null){
            mSaleNewsList = saleNewsBean.getTopic();
            mSaleNewsActivity.onSaleNewsSuccess(mSaleNewsList);
        }else{
            if (openLog) {
                Log.e(TAG, "数据请求失败" + saleNewsBean.getError() + ";" + saleNewsBean.getError_code());
            }
        }
    }
}
